Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
Why am I getting an array for $_POST['variable'] from an AJAX login form submission

I'm learning AJAX following the tutorials at https://www.w3schools.com/xml/ajax_intro.asp. I have succeffully completed a couple of GET requests, I'm now attempting a POST request.

My form:

<input class="form-control" type="email" id="log_email" required name="log_email">
<input class="form-control" type="password" id="log_password" required name="log_password">
<a class="btn" onclick="login(this)" >Log in</a>

My Ajax:

      <script type="text/javascript">
         function login(this_record) {
            var xhttp = new XMLHttpRequest();
            var UsrEml = $('#log_email').val();
            var UsrPw = $("#log_password").val();
            var AjaxURL = ("ajax_login.php") ;
            var AjaxPost = ("eml=" + UsrEml + "&pw=" + UsrPw);
            xhttp.onreadystatechange = function() {
             if (this.readyState == 4 && this.status == 200) {
              document.getElementById("accountstuff").innerHTML = this.responseText;
             }
           };
           xhttp.open("POST", AjaxURL, true);
           xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
           xhttp.send(AjaxPost);
         }        
      </script>

My PHP:

<?php
echo ($_POST["eml"]) ;
?>

The result is: Array ( [eml] => test@user.com [pw] => Password1 )

I was expecting: test@user.com

Why am I getting an array for a $_POST variable?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda